#include <fstream>
#include <iostream>

using namespace std;

int main ( int argc, char *argv[] )
{
  const int arraySizeIncrease = 1000000;
  int arraySize = arraySizeIncrease, wordCount = 0, numCount = 0;
  char** wordListArray = new char* [arraySize];
  char wordSize [512];
  int numSize [512];
  if ( argc != 3 )
	cout<<"usage: "<< argv[0] <<" <input_filename> <output_filename>\n";
  else {
    ifstream the_file ( argv[1] , ios::in|ios::binary );
    if ( !the_file.is_open() )
		cout<<"Could not open file\n";
    else {
		while (the_file >> wordSize )
		{
			wordListArray[wordCount] = new char [strlen (wordSize) + 1];
			strcpy (wordListArray[wordCount], wordSize);
			wordCount++;
			//If the File has more then 1000000 Words!
			if (wordCount % arraySizeIncrease == 0)
			{
				char** oldSize = wordListArray;
				arraySize += arraySizeIncrease;
				wordListArray = new char* [arraySize];
				memcpy (wordListArray, oldSize, wordCount * sizeof(char*));
				delete oldSize;
			}
		}
/*
		numArray = new int [wordCount];
		while (the_file >> numSize)
		{
		numArray[numCount] = numSize;
		numCount++;
		}
 */
 
	}
	the_file.close();
  }
  	FILE* fileOutputStream = fopen (argv[2], "wt");
	for (int cntIndex = 0; cntIndex < wordCount; cntIndex++)
	{
		fprintf (fileOutputStream, "%s\n", wordListArray[cntIndex]);
	}
/*
	for (int cntIndex = 0; cntIndex < numCount; cntIndex++)
	{
		fprintf (fileOutputStream, "%s\n", numArray[cntIndex]);
	}
*/
	fclose (fileOutputStream);

	for (int cntIndexN = 0; cntIndexN < wordCount; cntIndexN++)
	{
		delete wordListArray[cntIndexN];
	}
	delete wordListArray;
	wordListArray = NULL;
/*
	for (int cntIndexN = 0; cntIndexN < numCount; cntIndexN++)
	{
		delete numArray[cntIndexN];
	}
	delete numArray;
	numArray = NULL;
*/
	cout << "\nOutput file Written.\n\n";
}



/*

	String [][] numbers = new String [24][24];
 
	File file = new File("Currency Exchange Rates.csv");
 
	BufferedReader bufRdr  = new BufferedReader(new FileReader(file));
	String line = null;
	int row = 0;
	int col = 0;
 
	//read each line of text file
	while((line = bufRdr.readLine()) != null && row < 24)
	{	
	StringTokenizer st = new StringTokenizer(line,",");
	while (st.hasMoreTokens())
	{
		//get next token and store it in the array
		numbers[row][col] = st.nextToken();
		col++;
	}
	col = 0;
	row++;
	}
*/
